﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Globalization;
using System.Threading;
using System.Xaml;

namespace Geometry
{
    public static class XamlExtensions
    {
        public static void SaveXaml(this XmlWriter writer, object instance)
        {
            var invariantCulture = CultureInfo.InvariantCulture;
            var culture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = invariantCulture;
            XamlServices.Save(writer, instance);
            Thread.CurrentThread.CurrentCulture = culture;
        }

        public static object LoadXaml(this XmlReader reader)
        {
            var invariantCulture = CultureInfo.InvariantCulture;
            var culture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = invariantCulture;
            var result = XamlServices.Load(reader);
            Thread.CurrentThread.CurrentCulture = culture;
            return result;
        }
    }
}
